<template>
  <div class="wrapper">
    <div class="swiper-container">
      <div class="swiper-wrapper">
        <swiper-slide
          v-for="item of list"
          :key="item.index"
          class="swiper-no-swiping"
        >
          <keep-alive>
            <component :is="item.component"></component>
          </keep-alive>
        </swiper-slide>
      </div>
    </div>
  </div>
</template>

<script>
import Swiper from "swiper";
import one from "@/views/recommend/recommend.vue";
import two from "@/views/upcoming/upcoming.vue";
import Bscroll from "better-scroll";
export default {
  name: "Swiper",
  components: {
    one,
    two,
  },
  data() {
    return {
      swiperOptions: {},
      list: [
        { path: "tabone", component: one, index: 1 },
        { path: "tabtwo", component: two, index: 2 },
      ],
    };
  },
  mounted() {
    let mySwiper = new Swiper(".swiper-container", this.swiperOptions);
    this.$root.bus.$on("tabSwitch", (index) => {
      mySwiper.slideTo(index, 0, false);
    });

    mySwiper.on("slideChange", () => {
      console.log(mySwiper.activeIndex);
      this.$root.bus.$emit("pageSwitch", mySwiper.activeIndex);
    });

    this.scroll = new Bscroll(".wrapper", {
      click: true,
      scrollbar: true,
    });
    console.log("swiper--wrapper up!");
  },
};
</script>
<style lang="scss" scoped>
.wrapper {
  height: 82vh;
}
</style>